<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>辣妈优选</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <style media="screen">
        .content {
            width: 100%;
            padding: 0 15px;
            overflow: hidden;
        }

        .content ul {
            width: 100%;
            margin-top: 5px;
            overflow: hidden;
        }

        .content ul li {
            width: 49%;
            background-color: #fff;
            padding: 5px;
            float: left;
            margin-left: 2%;
            margin-top: 10px;
            box-sizing: border-box;
            min-height: 245px;
            overflow: hidden;
        }

        .content ul li:nth-child(2n+1) {
            margin-left: 0;
        }

        .content ul li>.goods_picture {
            width: 100%;
            height: 155px;
        }

        .content ul li>.goods_picture img {
            display: block;
            width: 100%;
            height: 100%;
        }

        .content ul li>.intro {
            width: 100%;
            overflow: hidden;
        }

        .content ul li>.intro span:first-child {
            width: 100%;
            overflow: hidden;
            margin-top: 3px;
            font-size: 12px;
        }

        .content ul li>.intro span:first-child img {
            display:inline-block;
            margin-top:2px;
            width:25px;
            height: 12px;
            margin-right:2px;
        }

        .content ul li>.price {
            width: 100%;
            overflow: hidden;
            display: flex;
            justify-content: space-between;
            margin-top: 8px;
        }

        .content ul li>.price .price_item {
            display: flex;
            width: auto;
        }

        .content ul li>.price .price_item:last-child {
            height: 15px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #999999;
            line-height: 15px;
        }

        .content ul li>.price .price_item span:nth-child(1) {
            width: auto;
            height: 15px;
            font-size: 10px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #999999;
            line-height: 17px;
        }

        .content ul li>.price .price_item span:nth-child(2) {
            width: auto;
            height: 15px;
            font-size: 10px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #FF4242;
            line-height: 17px;
        }

        .content ul li>.price .price_item span:nth-child(3) {
            width: auto;
            height: 15px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #FF4242;
            line-height: 15px;
        }

        [v-cloak] {
            display: none!important;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="wrap">
            <div class="content">
                <ul>
                    <li v-for='item in GuessLoveData' @click='openGoodsDtailsPage(item.goodsId)'>
                        <div class="goods_picture"><img :src="item.mainPic" v-cache-src="item.mainPic" alt=""></div>
                        <div class="intro">
                            <span class="aui-ellipsis-2" v-if='item.shopType==1'><img src="../../image/tm.png" alt="">{{item.dtitle}}</span>
                            <span class="aui-ellipsis-2" v-else><img src="../../image/tb_search.png" alt="">{{item.dtitle}}</span>
                            <!-- <span ></span> -->
                        </div>
                        <div class="price">
                            <div class="price_item"><span>券后</span><span>￥</span><span>{{item.actualPrice}}</span></div>
                            <div class="price_item">已售{{item.monthSales}}</div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/cling.js"></script>
<script type="text/javascript">
    /**
     * [注册一个全局自定义指令 `V-   cache-src`]
     * @param  {[type]} el      [需要图片缓存的元素]
     * @param  {[type]} binding [服务器图片对象数据]
     * @return {[type]}         [服务器图片地址]
     */
    Vue.directive('cache-src', function(el, binding) {
        if (binding) {
            setTimeout(function() {
                api.imageCache({
                    url: binding.value,
                    thumbnail: false
                }, function(ret, err) {
                    if (ret && ret.status) {
                        el.setAttribute("src", ret.url);
                    }
                });
            }, 100);
        }
    });
    apiready = function() {
        vm.init(4040);
        vm.initRefresh();
        vm.bottomLoad();
    }
    var vm = new Vue({
        el: '#app',
        data: {
            pageNo: 1,
            materialId: '',
            GuessLoveData: []
        },
        methods: {
            clearData: function() {
                vm.GuessLoveData = [];
            },
            init: function(materialId, isClick) {
                vm.materialId = materialId
                if (isClick) {
                    vm.pageNo += 1;
                } else { // 下拉刷新 或者 初次加载
                    vm.pageNo = 1;
                }
                cl.openLoading();
                api.ajax({
                    url: cl.apiServer + 'tb/optimusMaterial',
                    method: 'post',
                    headers: {
                        'Content-Type': 'application/json;charset=utf-8',
                        token:cl.userToken
                    },
                    data: {
                        body: {
                            materialId: materialId,
                            pageNo: vm.pageNo,
                            pageSize: 20,
                            version:cl.deviceInfo().appVersion,
                            mobileInfo:cl.systemType()
                        }
                    }
                }, function(ret, err) {
                    if (ret) {
                        console.log(JSON.stringify(ret));
                        if (ret.code == 0) {
                            cl.closeLoading();
                            if (ret.data.length >= 10) {
                                vm.no_more = false;
                                vm.GuessLoveData = vm.GuessLoveData.concat(ret.data);
                            } else if (ret.data.length == 0) {
                                vm.no_more = true;
                            } else {
                                vm.GuessLoveData = vm.GuessLoveData.concat(ret.data);
                            }

                        }
                    }
                });
            },
            //下拉刷新
            initRefresh: function() {
                cl.openRefresh(function() {
                    vm.init(vm.materialId, false);
                })
            },
            //上拉加载
            bottomLoad: function() {
                cl.scrollBottom(function() {
                    vm.init(vm.materialId, true);
                })
            },
            openGoodsDtailsPage: function(id) {
                console.log(id);
                cl.openWin({
                    name: 'goods_deatils',
                    pageParam: {
                        id: id
                    }
                })
            }
        }
    });
</script>

</html>
